<template>

  <div class="app-container">
    <el-form :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="患者名称" prop="patientName">
        <el-input
            v-model="queryParams.patientName"
            placeholder="请输入患者名称"
            clearable
            @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
        <el-button icon="Refresh" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

  <el-table v-loading="loading" :data="departmentList" @selection-change="handleSelectionChange">
    <el-table-column label="序号" align="center" prop="patientId" />
    <el-table-column prop="patientName" label="患者姓名" align="center" />
    <el-table-column prop="patientPhone" label="手机号" align="center" />
    <el-table-column prop="patientAge" label="年龄" align="center" />
    <el-table-column prop="inquiryCount" label="问诊次数" align="center" />
    <el-table-column prop="sumPayable" label="金额" align="center" />
    <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
      <template #default="scope">
        <el-button link type="primary"  @click="access(scope.row.patientName)">进入</el-button>
      </template>
    </el-table-column>
  </el-table>
    <pagination
        v-show="total>0"
        :total="total"
        v-model:page="queryParams.pageNum"
        v-model:limit="queryParams.pageSize"
        @pagination="getList"
    />

  </div>

</template>

<script setup name="patient">
import {listTable} from "@/api/manage/PatientManagement.js";
import {useRoute, useRouter} from "vue-router";
import { reactive, ref } from 'vue';


const { proxy } = getCurrentInstance();


const departmentList = ref([]);
const open = ref(false);
const loading = ref(true);
const showSearch = ref(true);
const ids = ref([]);
const single = ref(true);

const multiple = ref(true);
const total = ref(0);
const title = ref("");
const route = useRoute();
const router = useRouter();

const data = reactive({
  form: {},
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    departmentName: null,
  },
  rules: {

  }
});
const { queryParams, form, rules } = toRefs(data);

/** 查询科室列表 */
function getList() {
  loading.value = true;


  listTable(data.queryParams).then(response => {
    departmentList.value = response.data.rows;
    console.log(response)
    total.value = response.data.total;
    loading.value = false;
  });
}

function access(patientName){
  router.push({path:'/manage/PatientDetails',query:{patientName:patientName}});
}

// 取消按钮
function cancel() {
  open.value = false;
  reset();
}

// 表单重置
function reset() {
  form.value = {
    departmentId: null,
    departmentName: null,
    grade: null,
    score: null
  };
  proxy.resetForm("departmentRef");
}

/** 搜索按钮操作 */
function handleQuery() {
  queryParams.value.pageNum = 1;
  getList();
}

/** 重置按钮操作 */
function resetQuery() {
  proxy.resetForm("queryRef");
  handleQuery();
}

// 多选框选中数据
function handleSelectionChange(selection) {
  ids.value = selection.map(item => item.departmentId);
  single.value = selection.length != 1;
  multiple.value = !selection.length;
}

getList();
</script>
